package ks;

import java.util.ArrayList;

import ks.framework.common.Message;
import ks.framework.interfaces.IClientProcessor;

public class LocalClientProcessor implements IClientProcessor {

	boolean connected = false;
	
	/** Store all messages in queue to be inspected, retrieved. */
	ArrayList<Message> queue = new ArrayList<Message>(); 
	
	// helper method to reset state
	public void reset() {
		queue.clear();
		connected = false;
	}
	
	@Override
	public boolean process(Message m) {
		synchronized (queue) {
			queue.add(m);
		}
		
		return true;
	}

	/** retrieve the next message to be processed. */
	public Message dequeue() {
		Message m;
		
		synchronized (queue) {
			m = queue.remove(0);
		}
		
		return m;
	}
	
	@Override
	public void connected(boolean status) {
		this.connected = status;
	}

	/** Expose connected state. */
	public boolean isConnected() {
		return connected;
	}

}
